﻿namespace Sidvall.WorkItemManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class WebResult : global::Sidvall.WorkItemManager.UI.Entities.Core.BusinessBase, global::Sidvall.WorkItemManager.Data.IWebResult
    {
        #region Business Members

        #region ContentLength

        private System.Nullable<long> _ContentLength = null;
        partial void OnBeforeContentLengthPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData);
        partial void OnBeforeContentLengthPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterContentLengthPropertyChanged();
        public System.Nullable<long> ContentLength
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<long>>(_ContentLength);
                OnBeforeContentLengthPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _ContentLength);
                OnBeforeContentLengthPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("ContentLength", eventData.Value, true, true, true);
                    OnAfterContentLengthPropertyChanged();
                }
            }
        }

        #endregion
        #region ResponseTime

        private System.Nullable<System.TimeSpan> _ResponseTime = null;
        partial void OnBeforeResponseTimePropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<System.TimeSpan>> eventData);
        partial void OnBeforeResponseTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData);
        partial void OnAfterResponseTimePropertyChanged();
        public System.Nullable<System.TimeSpan> ResponseTime
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<System.TimeSpan>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<System.TimeSpan>>(_ResponseTime);
                OnBeforeResponseTimePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>>(value, _ResponseTime);
                OnBeforeResponseTimePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("ResponseTime", eventData.Value, true, true, true);
                    OnAfterResponseTimePropertyChanged();
                }
            }
        }

        #endregion
        #region StatusCode

        private System.Nullable<global::System.Net.HttpStatusCode> _StatusCode = global::System.Net.HttpStatusCode.OK;
        partial void OnBeforeStatusCodePropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<global::System.Net.HttpStatusCode>> eventData);
        partial void OnBeforeStatusCodePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<global::System.Net.HttpStatusCode>> eventData);
        partial void OnAfterStatusCodePropertyChanged();
        public System.Nullable<global::System.Net.HttpStatusCode> StatusCode
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<global::System.Net.HttpStatusCode>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<global::System.Net.HttpStatusCode>>(_StatusCode);
                OnBeforeStatusCodePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<global::System.Net.HttpStatusCode>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<global::System.Net.HttpStatusCode>>(value, _StatusCode);
                OnBeforeStatusCodePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("StatusCode", eventData.Value, true, true, true);
                    OnAfterStatusCodePropertyChanged();
                }
            }
        }

        #endregion
        #region WebAddress

        private string _WebAddress = string.Empty;
        partial void OnBeforeWebAddressPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeWebAddressPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterWebAddressPropertyChanged();
        public string WebAddress
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_WebAddress);
                OnBeforeWebAddressPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _WebAddress);
                OnBeforeWebAddressPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WebAddress", eventData.Value, true, true, true);
                    OnAfterWebAddressPropertyChanged();
                }
            }
        }

        #endregion
        #region WebExecutionContextId

        private int _WebExecutionContextId = 0;
        partial void OnBeforeWebExecutionContextIdPropertyGet(Sidvall.Business.PropertyEventData<int> eventData);
        partial void OnBeforeWebExecutionContextIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<int> eventData);
        partial void OnAfterWebExecutionContextIdPropertyChanged();
        public int WebExecutionContextId
        {
            get
            {
                Sidvall.Business.PropertyEventData<int> eventData = new Sidvall.Business.PropertyEventData<int>(_WebExecutionContextId);
                OnBeforeWebExecutionContextIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<int> eventData = new Sidvall.Business.PropertyChangeEventData<int>(value, _WebExecutionContextId);
                OnBeforeWebExecutionContextIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WebExecutionContextId", eventData.Value, true, true, true);
                    OnAfterWebExecutionContextIdPropertyChanged();
                }
            }
        }

        #endregion
        #region WebTargetId

        private System.Nullable<int> _WebTargetId = null;
        partial void OnBeforeWebTargetIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData);
        partial void OnBeforeWebTargetIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterWebTargetIdPropertyChanged();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public System.Nullable<int> WebTargetId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<int>>(_WebTargetId);
                OnBeforeWebTargetIdPropertyGet(eventData);
                return eventData.Value;
            }
            internal set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _WebTargetId);
                OnBeforeWebTargetIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WebTargetId", eventData.Value, true, true, true);
                    OnAfterWebTargetIdPropertyChanged();
                }
            }
        }

        #endregion
        #region WebExecutionContext

        private WebExecutionContext _WebExecutionContext;
        partial void OnBeforeWebExecutionContextPropertyChanged(Sidvall.Business.PropertyChangeEventData<WebExecutionContext> eventData);
        partial void OnAfterWebExecutionContextPropertyChanged();
        public WebExecutionContext WebExecutionContext
        {
            get
            {
                return _WebExecutionContext;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<WebExecutionContext> eventData = new Sidvall.Business.PropertyChangeEventData<WebExecutionContext>(value, _WebExecutionContext);
                OnBeforeWebExecutionContextPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WebExecutionContext", eventData.Value, true, true, false);
                    OnAfterWebExecutionContextPropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebResultManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowIsValid

        public override bool DataRowIsValid(Sidvall.Data.BusinessRuleFilter filter)
        {
            return global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebResultManager.DataRowIsValid(this, filter);
        }

        #endregion
        #region DataRowStateIsDirty

        public override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebResultManager.DataRowStateIsDirty(this);
            }
        }

        #endregion

        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebResultManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebResultManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public WebResult Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public WebResult Copy()
        {
            return Copy(null);
        }
        public WebResult Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new WebResult();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IWebResult item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IWebResult item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(WebResult destination, global::Sidvall.WorkItemManager.Data.IWebResult source, Sidvall.Data.CopySettings copySettings);
        private void Import(WebResult destination, global::Sidvall.WorkItemManager.Data.IWebResult source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebResultManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(WebResult destination, WebResult source, Sidvall.Data.CopySettings copySettings);
        private void Import(WebResult destination, WebResult source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.WorkItemManager.Data.IWebResult, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebResultManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebResultManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.WebResultManager.Initialize(this, settings);
        }

        #endregion
        
        #region IWebResult Members

        System.Nullable<long> global::Sidvall.WorkItemManager.Data.IWebResult.ContentLength
        {
            get
            {
                return this._ContentLength;
            }
            set
            {
                this._ContentLength = value;
            }
        }
        System.Nullable<System.TimeSpan> global::Sidvall.WorkItemManager.Data.IWebResult.ResponseTime
        {
            get
            {
                return this._ResponseTime;
            }
            set
            {
                this._ResponseTime = value;
            }
        }
        System.Nullable<global::System.Net.HttpStatusCode> global::Sidvall.WorkItemManager.Data.IWebResult.StatusCode
        {
            get
            {
                return this._StatusCode;
            }
            set
            {
                this._StatusCode = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IWebResult.WebAddress
        {
            get
            {
                return this._WebAddress;
            }
            set
            {
                this._WebAddress = value;
            }
        }
        int global::Sidvall.WorkItemManager.Data.IWebResult.WebExecutionContextId
        {
            get
            {
                return this._WebExecutionContextId;
            }
            set
            {
                this._WebExecutionContextId = value;
            }
        }
        System.Nullable<int> global::Sidvall.WorkItemManager.Data.IWebResult.WebTargetId
        {
            get
            {
                return this._WebTargetId;
            }
            set
            {
                this._WebTargetId = value;
            }
        }
        global::Sidvall.WorkItemManager.Data.IWebExecutionContext global::Sidvall.WorkItemManager.Data.IWebResult.WebExecutionContext
        {
            get
            {
                return this._WebExecutionContext;
            }
            set
            {
                UpdateChildProperty(this._WebExecutionContext, value);
                this._WebExecutionContext = value as WebExecutionContext;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public WebResult()
        {
        }

        public WebResult(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}